<?php

namespace addons\groupon\controller;

use addons\groupon\exception\Exception;
use addons\groupon\model\Store as ModelStore;
use addons\groupon\model\User;
use addons\groupon\model\UserStore;

class Store extends Base
{

    protected $noNeedLogin = ['nearby', 'detail'];
    protected $noNeedRight = ['*'];


    public function index()
    {
        $user = User::info();
        $userStore = UserStore::where('user_id', $user->id)->select();
        $store_id_arr = array_column($userStore, 'store_id');

        $stores = [];
        if ($store_id_arr) {
            $stores = ModelStore::show()->where('id', 'in', $store_id_arr)->select();
        }
        
        $this->success('获取自提点列表', $stores);
    }



    public function nearby()
    {
        $params = $this->request->get();

        $stores = ModelStore::getStoreList($params);

        $this->success('获取自提点列表', $stores);
    }


    public function detail() {
        $params = $this->request->get();

        $store = ModelStore::getStoreDetail($params);

        $this->success('获取自提点', $store);
    }
}
